package com.future.handler;


import com.future.exception.CodeException;
import com.future.exception.NullException;
import com.future.pojo.Judge;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Controller
@ResponseBody
public class GlobalExceptionHandlaer {

    @ExceptionHandler(value = NullException.class)
    public Judge NullException(Exception e){
        Judge judge = new Judge();
        judge.setStatusCode(-1);
        judge.setInfo(String.valueOf(e));
        return judge;
    }
    @ExceptionHandler(value = CodeException.class)
    public Judge CodeException(Exception e){
        Judge judge = new Judge();
        judge.setStatusCode(-1);
        judge.setInfo(String.valueOf(e));
        return judge;
    }
}
